/**
 * @DirectMemReporter.java  COPYRIGHT xiaojian
 * 
 * Created on 2019年12月24日 下午2:29:41
 */
package xj.toolkit.netty.util;

import java.lang.reflect.Field;
import java.util.concurrent.atomic.AtomicLong;

import org.springframework.util.ReflectionUtils;

import io.netty.util.internal.PlatformDependent;

/**
 * @author <a href="mailto:cxj2000@gmail.com">xiaojian.cao</a>
 *
 */
public class DirectMemReporter {

	public long getMax() {
		return PlatformDependent.maxDirectMemory();
	}

	public long getSize() {
		Field field = ReflectionUtils.findField(PlatformDependent.class, "DIRECT_MEMORY_COUNTER");
		field.setAccessible(true);
		try {
			return ((AtomicLong) field.get(PlatformDependent.class)).get();
		} catch (IllegalAccessException e) {
		}

		return 0L;
	}

}
